var numList =10;	//每页列数
var curPage = 1;  //默认第一页
var subPage=0;  //批量显示添加默认落点
var totalPage=9; //最多显示分页数
var countPage = 0;//页数总计
var selectJsonData = "";
function jsCk(t){
	if(!/^[1-9][0-9]*$/g.test(t.value)){
		t.value="";
		return false;
	}
}
var paging = {
	//加载分页
	"loadPage":function(data){
		var pCount = data.totalPages;//页数
		countPage = pCount;
		var pNums =  data.totalRecords;//总计条数
		var s1 = (totalPage-1)/2;
		var start_page = curPage - s1;
		var end_page = curPage + s1;
		if(start_page<=0){
			end_page = end_page - start_page + 1;
			start_page = 1;
		}
		if(end_page>pCount){
			end_page = pCount;
		}
		var prevHtml ='<a toPage="'+(curPage-1)+'" href="javascript:void(0);"   class="str">&lt;</a>';
		var nextHtml ='<a toPage="'+(curPage+1)+'" href="javascript:void(0);"  class="end" >&gt;</a>';
		if(curPage<2)prevHtml="";
		if(curPage>=pCount)nextHtml="";
		var ppHtml = "";
		for(i=start_page;i<=end_page;i++){
			var cur = "";
			if(curPage==i)cur='class="cur"';
			ppHtml = ppHtml+'<a toPage="'+i+'" href="javascript:void(0);"  '+cur+'>'+i+'</a>';
		}
		var pageHtml = '<span class="ic fl pr20 pCount">共<b>'+pNums+'</b>条记录</span><span class="sw fl pr20 columnsPage">显示 <a href="javascipr:void(0);" class="cur">10</a></span><span class="gopg fr"><span class="fl">跳转到</span><input type="button" class="btn" value="go"><input type="text" class="txt" min="1" onkeyup="jsCk(this)"></span><div class="pg fr pNumBtn">'+prevHtml+ppHtml+nextHtml+'</div>';
		var pageArea = $('#pageArea');
		pageArea.html(pageHtml);

		//每页显示指定的数量
		var dd = pNums/10;
		var ddHtmls = "";
		var pCur = 0;
		if(pNums>0&&pNums<11){
			pCur=3;
			pageArea.show();
		}else if(pNums>10&&pNums<21){
			pCur=2;
			pageArea.show();
		}else if(pNums>20&&pNums<51){
			pCur=1;
			pageArea.show();
		}else if(pNums>50&&pNums<101){
			pCur=0;
			pageArea.show();
		}else if(pNums==0){
			pCur=4;
			pageArea.hide();
		}
		$("#pageArea .columnsPage").html("显示 <a href='javascript:void(0);'>10</a><a href='javascript:void(0);'>20</a><a href='javascript:void(0);'>50</a><a href='javascript:void(0);'>100</a>");

		$("#pageArea .columnsPage a").removeClass("cur").eq(subPage).addClass("cur");
		var s = 3;
		for(var i=0;i<pCur;i++){
			$("#pageArea .columnsPage a").eq(s).remove();
			s -=1;
		}
	}
}

//点击触发换页的按钮
$("#pageArea .pNumBtn  a").live("click",function(){
	curPage=parseInt($(this).attr("toPage"));
	q.publicAjax(curPage,numList,selectJsonData);
});

//跳转
$("#pageArea .gopg .btn").live("click",function(){
	curPage=parseInt($("#pageArea .gopg .txt").val());
	//判断输入的页数是否大于最大的页数
	if(curPage>countPage){
		curPage=countPage;
	}
	if(curPage>0){
		q.publicAjax(curPage,numList,selectJsonData);
	}
	
});

//点击触发分批显示的按钮
$("#pageArea .columnsPage a").live("click",function(){
	numList=parseInt($(this).text());
	curPage=1;
	q.publicAjax(curPage,numList,selectJsonData);
	subPage=$(this).index();
}); 

